package org.com.behavioralPattern.observerPattern;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jonny
 * @version 1.0
 * @Description:
 * @date 2021/4/27 16:32
 */
public class Button implements Clickable{

    List<ClickableObserver> observers=new ArrayList<ClickableObserver>();

    String color;
    int x,y;


    @Override
    public void click() {
        System.out.println("按钮被单机了");
        for (int i=observers.size()-1;i>=0;i--){
            observers.get(i).clicked(this);
        }
    }

    @Override
    public void AddClickableObserver(ClickableObserver observer) {
        observers.add(observer);
    }

    @Override
    public void RemoveclickableObserve(ClickableObserver observer) {
        observers.remove(observer);
    }

    public String toString(){
        return "按钮颜色："+color+" ,坐标 "+x+" , "+y;
    }
}
